package com.sam.composition;

import java.util.Date;

public class ExtendTest {

	/**
	 * 继承的原则测试构造器不能调用可被覆盖的方法
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		Sub sub = new Sub();

		sub.overridingMethod();

	}

	public static class Super {

		public Super() {

			System.out.println("父类构造函数调用！");
			overridingMethod();
		}

		public void overridingMethod() {

			System.out.println("父类可覆盖方法调用！");
		}

	}

	public static class Sub extends Super {

		private final Date date;

		public Sub() {

			date = new Date();
			System.out.println("子类构造方法调用！");
		}

		@Override
		public void overridingMethod() {

			System.out.println(date);
			System.out.println("子类方法调用！");
		}

	}

}
